<?php
/*THIS PART MUST GO IN THE TOP, the first line index.php*/

/*DEVELOPEMENT -- DEBUG ERRORS*/

error_reporting(E_ALL);
ini_set('display_errors', '1');

/*-------------------*/

session_start(); /*Craft o load the session and load session vars*/

include ("gvar.php");
/*
LOGIN CONTROLLER.
>>> 
if(HasLogged()) {}
<<<
TRUE: The user/teacher has logged it in the database.
FALSE: Is anonymous (not logged) */

?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<title>Save a tree</title>
	<link href="style.css" rel="stylesheet" type="text/css" />
	<link href='http://fonts.googleapis.com/css?family=Monda' rel='stylesheet' type='text/css'>
</head>
<body>
	<div id="container" class="container">
		<div id="header" class="header">
			<div id="loginInfo"></div>
			<div id="loginButton">
				<a id="loginLink" href="login.php">Àrea del professorat</a>
			</div>
		</div>
		<div id="content">
			<div id="center" class="center">				
				<form method="POST" action="#" name="select">
					<select name="grd" class="styled-select">
						<option value="">Seleccioni un curs</option>
						<?php 
							$grade = 'SELECT * FROM Grade';

							if($r = mysql_query($grade,$dbc)) {
								while ($row = mysql_fetch_array($r)){
									echo '<option value="'.$row['Name'].'"'.($row['Name'] == @$_POST["grd"] ? ' selected' : '') .'>'.$row['Name'].'</option>';
								}
							}
					 	?>
					</select>
					<select name="sbj" class="styled-select">
						<option value="">Seleccioni una assignatura</option>
						<?php
							$subject = 'SELECT * FROM Subject';

							if($r = mysql_query($subject,$dbc)) {
								while ($row = mysql_fetch_array($r)){
									echo '<option value="'.$row['Name'].'"'.($row['Name'] == @$_POST["sbj"] ? ' selected' : '') .'>'.$row['Name'].'</option>';
								}
							}
					 	?>
					</select>
					<select name="tchr" class="styled-select">
						<option value="">Seleccioni un professor</option>
						<?php 
							$user = 'SELECT * FROM User';

							if($r = mysql_query($user,$dbc)) {
								while ($row = mysql_fetch_array($r)){
									echo '<option value="'.$row['UserName'].'"'.($row['UserName'] == @$_POST["tchr"] ? ' selected' : '') .'>'.$row['UserName'].'</option>';
								}
							}
					 	?>
					</select>
					<input type="submit" class="button" value="Veure documents" />
				</form>
				<div id="filterEmpty"></div>
				<div id="upload">
					<?php if(HasLogged()){ ?>
						<center><form method="post" action="upload.php"><input type="submit" class="button" value="Pujar fitxer" /></form></center>
					<?php } ?>
				</div>
				<br>
				<?php require('display.php'); ?>
			</div>
		</div>
	</div>
	<?php if(HasLogged()) { echo '<script type="text/javascript">
										document.getElementById("loginInfo").innerHTML="Benvingut, '.$_SESSION["logID"].'";
										document.getElementById("loginLink").innerHTML="Tanca la sessió";
										document.getElementById("loginLink").href="logout.php";
								  </script>';
	} ?>
	<script type='text/javascript'>
		var registers = document.getElementById('registers');
		if(registers == null)
			document.getElementById('filterEmpty').innerHTML='Cap entrada correspon amb el filtre seleccionat';
	</script>					  
</body>
</html>